@echo off
setlocal enabledelayedexpansion

:: Set title
title Deploy to Linux Server

:: Save current directory
set "CURRENT_DIR=%cd%"

:: Get user input
set /p "HOST_IP=Enter server IP address: "
set /p "PORT=Enter SSH port (default 22): " || set "PORT=22"
set /p "USERNAME=Enter username: "
set /p "REMOTE_PATH=Enter remote path (e.g. /home/username): "

:: Confirm information
echo.
echo Please confirm the following information:
echo Server IP: %HOST_IP%
echo Port: %PORT%
echo Username: %USERNAME%
echo Remote Path: %REMOTE_PATH%
echo.
set /p "CONFIRM=Is this information correct? (Y/N): "

if /i not "%CONFIRM%"=="Y" (
    echo Operation cancelled
    goto :EOF
)

:: Create temp directory and copy files
echo.
echo Preparing files...
set "TEMP_DIR=%TEMP%\deploy_temp"
if exist "%TEMP_DIR%" rd /s /q "%TEMP_DIR%"
mkdir "%TEMP_DIR%"

:: Copy only necessary files, excluding .pyc and other temp files
robocopy "..\main" "%TEMP_DIR%\main" /E /XF *.pyc *.pyo *.pyd __pycache__* /XD __pycache__

:: Use scp command to upload files
echo.
echo Uploading files...
scp -P %PORT% -r "%TEMP_DIR%\main" "%USERNAME%@%HOST_IP%:%REMOTE_PATH%"

:: Check upload result
if %ERRORLEVEL% equ 0 (
    echo.
    echo Deployment successful!
) else (
    echo.
    echo Deployment failed. Please check your network connection and authentication.
)

:: Clean up temp files
rd /s /q "%TEMP_DIR%"

:: Wait for user confirmation
echo.
pause

endlocal 